package com.sicheng.lc.杂题.位运算;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/7/17 22:37
 */
public class 只出现一次的数字II {
    //https://leetcode.cn/problems/single-number-ii/
    public int singleNumber(int[] nums) {
        int[] bits = new int[32];
        for (int num : nums) {
            for (int i = 0; i < bits.length; i++) {
                if ((num >> i & 1) == 1) {
                    bits[i] = (bits[i] + 1) % 3;
                }
            }
        }

        int res = 0;
        for (int i = 0; i < bits.length; i++) {
            res |= bits[i] * (1 << i);
        }
        return res;
    }
}
